<template>
    <!-- 成绩列表 -->
    <h2>成绩</h2>
    <table cellspacing="0">
        <tr>
            <td>科目</td>
            <td>分数</td>
        </tr>
        <tr>
            <td style="font-size: 18px; font-weight: bold;">总科</td>
            <td style="font-size: 18px; font-weight: bold;">{{ num }}</td>
        </tr>
        <tr v-for="item in list">
            <td>{{ item.name }}</td>
            <td>{{ item.score }}</td>
        </tr>
    </table>
    <!-- 折线图 -->
    <h2>成绩变化</h2>
    <div id="main"></div>
    <!-- 小结 -->
    <h2>小结</h2>
    <p>这次成绩不错，跟你以往相比，变化不大，继续努力哦。</p>
    <p>做到以下2点，下次可能会更好哦</p>
    <p>1.各学科共同进步，才能全面提升</p>
    <p>2.保持平稳的心态，查缺补漏，才能再创新高</p>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
import { defineProps, onMounted, ref, nextTick } from 'vue'

const info = defineProps(["list", 'num']);
const cate = ref([])
const sco = ref([])

info.list.forEach(item => {
    cate.value.push(item.name)
    sco.value.push(item.score)
})

onMounted(() => {
    nextTick(() => {
        type EChartsOption = echarts.EChartsOption;
        var chartDom = document.getElementById('main')!;
        var myChart = echarts.init(chartDom);
        var option: EChartsOption;

        option = {
            xAxis: {
                type: 'category',
                data: cate.value
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data: sco.value,
                    type: 'line',
                    smooth: true
                }
            ]
        };

        option && myChart.setOption(option);
    })
})


</script>

<style scoped lang="scss">
h2 {
    height: 30px;
    padding-left: 10px;
    background-color: #74ede4;
    line-height: 30px;
}

table {
    width: 300px;
    height: 500px;
    /* border: 1px solid #b; */
    margin: 5px auto 0;
    text-align: center;

    tr,
    td {
        border: 1px solid black;
    }
}

#main {
    height: 300px;
}

p {
    font-size: 16px;
    margin-left: 10px;
}
</style>